;(function(doc) {

	var oList = doc.getElementsByClassName("list")[0],
			oItems = oList.getElementsByClassName("list-item"),
			curIdx = 0;

	function init() {
		bindEvent();
	}

	function bindEvent() {
		/**
		 * 方法一：绑定移入事件
		 * 绑定事件处理函数元素不多的情况下可以使用
		 * 使用for绑定事件处理函数
		 */ 
		// for(var i = 0; i < oItems.length; i ++) {
		// 	addEvent(oItems[i], 'mouseover', function() {
		// 		oItems[curIdx].className = 'list-item';
		// 		curIdx = Array.prototype.indexOf.call(oItems, this);
		// 		oItems[curIdx].className += ' active';
				
		// 	});
		// }

		/**
		 * 方法二：事件委托绑定移入事件
		 */ 
    // addEvent(oList, 'mouseover', slide);

    /**
     * 方法三：事件委托绑定移入事件 给document绑定mousemove事件
     */ 
    addEvent(oList, 'mouseover', function() {
    	addEvent(document, 'mousemove', slide);
    });

    addEvent(oList, 'mouseout', function() {
    	removeEvent(document, 'mousemove', slide);
    })


	}

	function slide(ev) {
		var e = ev || window.event,
				tar = e.target || e.srcElement,
				oParent = getParent(tar, 'li'),
				thisIdx = Array.prototype.indexOf.call(oItems, oParent);


		if(curIdx !== thisIdx) {
			oItems[curIdx].className = 'list-item';
			curIdx = thisIdx;
			oItems[curIdx].className += ' active';
		}

	}

	// 根据子级元素target寻找父级元素element
	function getParent(target, element) {
		while(target.tagName.toLowerCase() !== element) {
			target = target.parentNode;
		}

		return target;
	}

	init();

})(document);